|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
WSDLBindingFactory.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* $Id: WSDLBindingFactory.java,v 1.1 2004/12/15 14:18:16 patforna Exp $
|
|
3 |
*
|
|
4 |
* Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
|
|
5 |
* Berne University of Applied Sciences
|
|
6 |
* School of Engineering and Information Technology
|
|
7 |
* All rights reserved.
|
|
8 |
*/
|
|
9 |
package bexee.wsdl;
|
|
10 |
|
|
11 |
import java.util.Iterator;
|
|
12 |
import java.util.List;
|
|
13 |
import java.util.Map;
|
|
14 |
|
|
15 |
import javax.wsdl.Binding;
|
|
16 |
import javax.wsdl.BindingFault;
|
|
17 |
import javax.wsdl.BindingInput;
|
|
18 |
import javax.wsdl.BindingOperation;
|
|
19 |
import javax.wsdl.BindingOutput;
|
|
20 |
import javax.wsdl.Definition;
|
|
21 |
import javax.wsdl.Fault;
|
|
22 |
import javax.wsdl.Input;
|
|
23 |
import javax.wsdl.Operation;
|
|
24 |
import javax.wsdl.Output;
|
|
25 |
import javax.wsdl.Port;
|
|
26 |
import javax.wsdl.PortType;
|
|
27 |
import javax.wsdl.Service;
|
|
28 |
import javax.wsdl.WSDLException;
|
|
29 |
import javax.wsdl.extensions.ExtensibilityElement;
|
|
30 |
import javax.wsdl.extensions.ExtensionRegistry;
|
|
31 |
import javax.wsdl.extensions.soap.SOAPAddress;
|
|
32 |
import javax.wsdl.extensions.soap.SOAPBinding;
|
|
33 |
import javax.wsdl.extensions.soap.SOAPBody;
|
|
34 |
import javax.wsdl.extensions.soap.SOAPFault;
|
|
35 |
import javax.wsdl.extensions.soap.SOAPOperation;
|
|
36 |
import javax.xml.namespace.QName;
|
|
37 |
|
|
38 |
import bexee.util.Constants;
|
|
39 |
|
|
40 |
/**
|
|
41 |
* This class is used as a WSDL:Binding and WSDL:Service factory. It will be
|
|
42 |
* used for the generation of concrete bindings and services for abstract web
|
|
43 |
* services.
|
|
44 |
*
|
|
45 |
* @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:16 $
|
|
46 |
* @author Patric Fornasier
|
|
47 |
* @author Pawel Kowalski
|
|
48 |
*/
|
|
49 |
public class WSDLBindingFactory { |
|
50 |
|
|
51 |
/**
|
|
52 |
* Add a binding information to the Definitions instance. Uses the given URI
|
|
53 |
* String as the service location.
|
|
54 |
*
|
|
55 |
* @param definition
|
|
56 |
* @param uri
|
|
57 |
* @return @throws
|
|
58 |
* WSDLException
|
|
59 |
*/
|
|
60 | 0 |
public Definition addBinding(Definition definition, String uri)
|
61 |
throws WSDLException {
|
|
62 |
|
|
63 | 0 |
ExtensionRegistry extReg = definition.getExtensionRegistry(); |
64 |
|
|
65 |
// create and add operationbindings
|
|
66 | 0 |
Map portTypes = definition.getPortTypes(); |
67 | 0 |
for (Iterator iter = portTypes.values().iterator(); iter.hasNext();) {
|
68 | 0 |
PortType portType = (PortType) iter.next(); |
69 |
|
|
70 |
// create and add a binding
|
|
71 | 0 |
Binding binding = getBinding(portType, definition); |
72 | 0 |
definition.addBinding(binding); |
73 |
|
|
74 |
// create and add a service
|
|
75 | 0 |
definition |
76 |
.addService(getService(binding, portType, definition, uri)); |
|
77 |
} |
|
78 |
|
|
79 |
// add the soap address to the definition
|
|
80 | 0 |
definition.addNamespace(Constants.WSDL_SOAP_PPREFIX, |
81 |
Constants.URI_WSDL_SOAP); |
|
82 | 0 |
definition.addNamespace(Constants.WSDL_PRFIX, Constants.URI_WSDL); |
83 |
|
|
84 | 0 |
return definition;
|
85 |
} |
|
86 |
|
|
87 | 0 |
private Service getService(Binding binding, PortType portType,
|
88 |
Definition def, String uri) throws WSDLException {
|
|
89 |
|
|
90 | 0 |
ExtensionRegistry extReg = def.getExtensionRegistry(); |
91 |
|
|
92 |
// create a service for the portType
|
|
93 | 0 |
Service service = def.createService(); |
94 | 0 |
service.setQName(new QName(portType.getQName().getNamespaceURI(),
|
95 |
portType.getQName().getLocalPart() + Constants.SERVICE_SUFFIX)); |
|
96 |
|
|
97 |
// create a port and add it to the service
|
|
98 | 0 |
Port port = def.createPort(); |
99 | 0 |
port.setBinding(binding); |
100 | 0 |
port.setName(portType.getQName().getLocalPart()); |
101 | 0 |
service.addPort(port); |
102 |
|
|
103 |
// create a soapaddress and add it to the port
|
|
104 | 0 |
SOAPAddress soapAddress = (SOAPAddress) extReg.createExtension( |
105 |
Port.class, Constants.SOAP_ADDRESS_QNAME);
|
|
106 | 0 |
soapAddress.setLocationURI(uri); |
107 | 0 |
port.addExtensibilityElement(soapAddress); |
108 |
|
|
109 | 0 |
return service;
|
110 |
} |
|
111 |
|
|
112 | 0 |
private Binding getBinding(PortType portType, Definition def)
|
113 |
throws WSDLException {
|
|
114 |
|
|
115 | 0 |
ExtensionRegistry extReg = def.getExtensionRegistry(); |
116 |
|
|
117 |
// Create a binding
|
|
118 | 0 |
Binding binding = def.createBinding(); |
119 | 0 |
binding.setUndefined(false);
|
120 | 0 |
binding.setQName(new QName(portType.getQName().getNamespaceURI(),
|
121 |
portType.getQName().getLocalPart() |
|
122 |
+ Constants.SOAP_BINDING_SUFFIX)); |
|
123 | 0 |
binding.setPortType(portType); |
124 |
|
|
125 |
// create a soapbinding
|
|
126 | 0 |
SOAPBinding soapBinding = (SOAPBinding) extReg.createExtension( |
127 |
Binding.class, Constants.SOAP_BINDING_QNAME);
|
|
128 | 0 |
soapBinding.setStyle(bexee.util.Constants.DEFAULT_STYLE); |
129 | 0 |
soapBinding.setTransportURI(bexee.util.Constants.URI_SOAP_HTTP); |
130 |
|
|
131 |
// add the soapbinding
|
|
132 | 0 |
binding.addExtensibilityElement(soapBinding); |
133 |
|
|
134 |
// create and add operationbindings
|
|
135 | 0 |
List operations = portType.getOperations(); |
136 | 0 |
for (Iterator iterator = operations.iterator(); iterator.hasNext();) {
|
137 | 0 |
Operation operation = (Operation) iterator.next(); |
138 | 0 |
binding.addBindingOperation(getBindingOperation(operation, def)); |
139 |
} |
|
140 |
|
|
141 | 0 |
return binding;
|
142 |
} |
|
143 |
|
|
144 | 0 |
private BindingOperation getBindingOperation(Operation operation,
|
145 |
Definition definition) throws WSDLException {
|
|
146 |
|
|
147 |
// get the extension registry for element creation
|
|
148 | 0 |
ExtensionRegistry extReg = definition.getExtensionRegistry(); |
149 |
|
|
150 |
// create the parts of the BindingOperation
|
|
151 | 0 |
BindingOperation bindingOper = definition.createBindingOperation(); |
152 | 0 |
BindingInput bindingInput = definition.createBindingInput(); |
153 | 0 |
BindingOutput bindingOutput = definition.createBindingOutput(); |
154 |
|
|
155 |
// set properties of the BindingOperation
|
|
156 | 0 |
bindingOper.setName(operation.getName()); |
157 | 0 |
bindingOper.setOperation(operation); |
158 |
|
|
159 |
// create a soapoperation and set it
|
|
160 | 0 |
SOAPOperation soapOper = (SOAPOperation) extReg.createExtension( |
161 |
BindingOperation.class, Constants.SOAP_OPERATION_QNAME);
|
|
162 | 0 |
soapOper.setSoapActionURI("");
|
163 | 0 |
bindingOper.addExtensibilityElement(soapOper); |
164 |
|
|
165 |
// Input clause
|
|
166 | 0 |
bindingOper.setBindingInput(getBindingInput(operation.getInput(), |
167 |
definition)); |
|
168 |
|
|
169 |
// Output clause
|
|
170 | 0 |
bindingOper.setBindingOutput(getBindingOutput(operation.getOutput(), |
171 |
definition)); |
|
172 |
|
|
173 |
// Faults clause
|
|
174 | 0 |
Map faults = operation.getFaults(); |
175 | 0 |
for (Iterator iter = faults.values().iterator(); iter.hasNext();) {
|
176 | 0 |
Fault fault = (Fault) iter.next(); |
177 | 0 |
bindingOper.addBindingFault(getBindingFault(fault, definition)); |
178 |
} |
|
179 |
|
|
180 | 0 |
return bindingOper;
|
181 |
} |
|
182 |
|
|
183 | 0 |
private BindingInput getBindingInput(Input input, Definition definition)
|
184 |
throws WSDLException {
|
|
185 |
|
|
186 |
// create an input and set properties
|
|
187 | 0 |
BindingInput bindInput = definition.createBindingInput(); |
188 | 0 |
bindInput.setName(input.getMessage().getQName().getLocalPart()); |
189 |
|
|
190 | 0 |
bindInput.addExtensibilityElement(getSOAPBody(bindInput.getClass(), |
191 |
definition)); |
|
192 |
|
|
193 | 0 |
return bindInput;
|
194 |
} |
|
195 |
|
|
196 | 0 |
private BindingOutput getBindingOutput(Output output, Definition definition)
|
197 |
throws WSDLException {
|
|
198 |
|
|
199 |
// create an input and set properties
|
|
200 | 0 |
BindingOutput bindOutput = definition.createBindingOutput(); |
201 | 0 |
bindOutput.setName(output.getMessage().getQName().getLocalPart()); |
202 |
|
|
203 | 0 |
bindOutput.addExtensibilityElement(getSOAPBody(bindOutput.getClass(), |
204 |
definition)); |
|
205 | 0 |
return bindOutput;
|
206 |
} |
|
207 |
|
|
208 | 0 |
private BindingFault getBindingFault(Fault fault, Definition definition)
|
209 |
throws WSDLException {
|
|
210 |
|
|
211 | 0 |
BindingFault bindingFault = definition.createBindingFault(); |
212 | 0 |
bindingFault.setName(fault.getName()); |
213 | 0 |
bindingFault.addExtensibilityElement(getSOAPFault(bindingFault, |
214 |
definition)); |
|
215 |
|
|
216 | 0 |
return bindingFault;
|
217 |
|
|
218 |
} |
|
219 |
|
|
220 | 0 |
private ExtensibilityElement getSOAPBody(Class clazz, Definition definition)
|
221 |
throws WSDLException {
|
|
222 |
|
|
223 |
// get the extension registry for element creation
|
|
224 | 0 |
ExtensionRegistry extReg = definition.getExtensionRegistry(); |
225 |
|
|
226 |
// create a soapbody
|
|
227 | 0 |
SOAPBody soapBody = (SOAPBody) extReg.createExtension(clazz |
228 |
.getInterfaces()[0], Constants.SOAP_BODY_QNAME); |
|
229 |
|
|
230 |
// set properties
|
|
231 | 0 |
soapBody.setUse(Constants.DEFAULT_USE); |
232 | 0 |
soapBody.setEncodingStyles(Constants.ENCODING_STYLES); |
233 | 0 |
soapBody.setNamespaceURI(definition.getTargetNamespace()); |
234 |
|
|
235 | 0 |
return soapBody;
|
236 |
} |
|
237 |
|
|
238 | 0 |
private SOAPFault getSOAPFault(BindingFault fault, Definition definition)
|
239 |
throws WSDLException {
|
|
240 |
|
|
241 |
// get the extension registry for element creation
|
|
242 | 0 |
ExtensionRegistry extReg = definition.getExtensionRegistry(); |
243 |
|
|
244 | 0 |
SOAPFault soapFault = (SOAPFault) extReg.createExtension( |
245 |
BindingFault.class, Constants.SOAP_FAULT_QNAME);
|
|
246 |
|
|
247 | 0 |
soapFault.setUse(Constants.DEFAULT_USE); |
248 | 0 |
soapFault.setEncodingStyles(Constants.ENCODING_STYLES); |
249 |
|
|
250 | 0 |
return soapFault;
|
251 |
} |
|
252 |
|
|
253 |
} |
|